﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
using System.Windows;
namespace UIAutoMation.Controllers
{

    public class InWecaht {
        
    }

    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        //根据名称获取窗体句柄
        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
        //根据句柄获取进程ID
        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        public void Get()
        {
            var rng = new Random();
            int weChatID = 0;

            IntPtr hwnd =FindWindow(null, "微信");

            if (hwnd != IntPtr.Zero)
            {
                GetWindowThreadProcessId(hwnd, out weChatID);
            }

            //AutomationElement root = new AutomationElement();
           




        }
       
    }
}
